package algorithm.array;

/**
 * 寻找最大连续1的个数
 */
public class FindMaxConsecutiveOnes {

    public static void main(String[] args) {
        int [] arr = {1,1,0,1};
        System.out.println(findMaxConsecutiveOnes(arr));
    }

    public static int findMaxConsecutiveOnes(int[] nums) {

        //比较当前连续1和之前连续1的最大值
        int maxCount = 0;
        //当前最长连续1
        int count = 0;

        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 1){
                count ++;
            }else{
                maxCount = Math.max(maxCount,count);
                count = 0;
            }
        }
        maxCount = Math.max(maxCount,count);

        return maxCount;
    }
}
